﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using System.Data;

namespace WebPresentation
{
    public partial class Role : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ImageButtonadd_Click(object sender, ImageClickEventArgs e)
        {
            RoleBO role = new RoleBO();
            string name = txtrolename.Text;
            if (role.AddNewRoll(name) > 0)
            {
                Label10.Text = "Add successfully";
                dtgrole.DataBind();
            }
            else
            {
                Label10.Text = "Add failed";
            }
        }

        protected void ImageButtonEdit_Click(object sender, ImageClickEventArgs e)
        {
            RoleBO role = new RoleBO();
            string name = txtrolename.Text;
            int id = Int32.Parse(Label11.Text);
            if (role.UpdateRoll(name,id) > 0)
            {
                Label10.Text = "Update successfully";
                dtgrole.DataBind();
            }
            else
            {
                Label10.Text = "Update failed";
            }
        }

        protected void ImageButtonDel_Click(object sender, ImageClickEventArgs e)
        {
            RoleBO role = new RoleBO();
            int id = Int32.Parse(Label11.Text);
            if (role.DeleteRoll(id) > 0)
            {
                Label10.Text = "Delete successfully";
                dtgrole.DataBind();
            }
            else
            {
                Label10.Text = "Delete failed";
            }
        }

        protected void dtgrole_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = dtgrole.SelectedRow;
            txtrolename.Text = row.Cells[2].Text;
            Label11.Text = row.Cells[1].Text;
        }
    }
}